package cn.com.joyplus.wechat.controller;

import cn.com.joyplus.wechat.service.WechatCommonApiService;
import cn.com.joyplus.wechat.service.WechatCoreApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created by 王灏川(wangrs@qq.com) on 2017/8/11 0011.
 */
@Controller
@RequestMapping(value = "wxapi", produces = "text/plain;charset=UTF-8")
public class WxApiController {
    private static final Logger logger = LoggerFactory.getLogger(WxApiController.class);


    @Autowired
    WechatCoreApiService wechatCoreApiService;

    @Autowired
    WechatCommonApiService wechatCommonApiService;



    @RequestMapping("/get-accesstoken")
    @ResponseBody
    public String getAccessToken() {
        return wechatCoreApiService.getWechatAccessToken();
    }

    @RequestMapping(value = "call-post-api", method = {RequestMethod.POST})
    @ResponseBody
    public String callWechatApi(@RequestParam String code ,@RequestBody String params) {
        try {
            return wechatCommonApiService.callCommonApi(code,params);
        } catch (Exception e) {
            return e.getMessage();
        }
    }

    @RequestMapping(value = "call-get-api", method = {RequestMethod.GET})
    @ResponseBody
    public String callWechatApi(@RequestParam String code) {
        try {
            return wechatCommonApiService.callCommonApi(code);
        } catch (Exception e) {
            return e.getMessage();
        }
    }

}
